package com.framework.base.proxy;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @author chaolong.jin
 * @description
 * @date 2019/05/05 10:00
 */
public class CglibProxy implements MethodInterceptor {

    private Object object;

    public CglibProxy(Object object) {
        this.object = object;
    }
    public Object getInstance(){
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(object.getClass());
        enhancer.setCallback(this);
        return enhancer.create();
    }
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("proxy invoke");
        Object result=method.invoke(object,objects);
        return result;
    }

    public static void main(String[] args) {
        UserCenterCaseEnum CASE_ENUM = UserCenterCaseEnum.valueOf("SIMPLE");
        CASE_ENUM = null;

    }

}
